unit DuplicataPagarRecordFr;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
  StdCtrls, DBCtrls, ActnList, Buttons, ComCtrls, ExtCtrls, MainRecordFr;

type

  { TDuplicataPagarRecordFrame }

  TDuplicataPagarRecordFrame = class(TMainRecordFrame)
    BtnFornecedor: TBitBtn;
    DBCalendarData: TDBCalendar;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    PlanoContaLookup: TDBLookupComboBox;
    Label6: TLabel;
    parcelaEdit: TDBEdit;
    Label4: TLabel;
    NomePessoaDBEDit: TDBEdit;
    IdDuplicataDBEdit: TDBEdit;
    IdFornecedorDBEdit: TDBEdit;
    DataVencimentoDBEDit: TDBEdit;
    ToolButton3: TToolButton;
    ValorDuplicataDBEDit: TDBEdit;
    observacaoDBEdit: TDBMemo;
    Label1: TLabel;
    Label5: TLabel;
    Valor: TLabel;
    status: TDBRadioGroup;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    Clonar: TToolButton;
    procedure BtnFornecedorClick(Sender: TObject);
    procedure ClonarClick(Sender: TObject);
    procedure DBCalendarDataClick(Sender: TObject);
    procedure FecharActionExecute(Sender: TObject);
    procedure InsereValores(IdFornecedor, Nome, DataVencimento,
      valorDuplicata, observacao, parcela: string);
    procedure ControlaBotoes(); override;
    procedure InserirActionExecute(Sender: TObject);
    procedure SalvarActionExecute(Sender: TObject);

  private
    { private declarations }
  public
    { public declarations }
  end;

//!Verificar como alterar o Status da duplicata

implementation

uses Initializator, MainFr, DuplicatasDM;

procedure TDuplicataPagarRecordFrame.BtnFornecedorClick(Sender: TObject);
begin
  TheControl.ShowForeignFrame(TMainFrame(FornecedorSearchFrame));
end;

procedure TDuplicataPagarRecordFrame.ClonarClick(Sender: TObject);
var
  IdFornecedor, Nome, DataVencimento, ValorDupl, observacao, parcela: string;
begin
  if IdFornecedorDBEdit.Text <> '' then begin
    IdFornecedor := IdFornecedorDBEdit.Text;
    Nome := NomePessoaDBEDit.Text;
    DataVencimento := DataVencimentoDBEDit.Text;
    ValorDupl := ValorDuplicataDBEDit.Text;
    observacao := observacaoDBEdit.Text;
    parcela := parcelaEdit.Text;

    DuplicataData.SalvaDuplicataPagarClonagem();
    InsereValores(IdFornecedor, Nome, DataVencimento,
      ValorDupl, observacao, parcela);
    ControlaBotoes();
  end;
end;

procedure TDuplicataPagarRecordFrame.DBCalendarDataClick(Sender: TObject);
begin
  DataVencimentoDBEDit.Text := DBCalendarData.Date;
end;

procedure TDuplicataPagarRecordFrame.FecharActionExecute(Sender: TObject);
begin
  inherited;
  TheControl.ShowFrame(TMainFrame(DuplicatasFrame));
end;

procedure TDuplicataPagarRecordFrame.InsereValores(IdFornecedor, Nome,
  DataVencimento, valorDuplicata, observacao, parcela: string);
begin
  status.ItemIndex := 0;
  IdDuplicataDBEdit.Text := '';
  IdFornecedorDBEdit.Text := IdFornecedor;
  NomePessoaDBEDit.Text := Nome;
  DataVencimentoDBEDit.Text := DataVencimento;
  ValorDuplicataDBEDit.Text := valorDuplicata;
  observacaoDBEdit.Text := observacao;
  parcelaEdit.Text := FloatToStr(StrToFloatDef(parcela, 1) + 1);
end;

procedure TDuplicataPagarRecordFrame.ControlaBotoes();
begin
  inherited ControlaBotoes;
  Clonar.Enabled := AlterarAction.Enabled;
end;

procedure TDuplicataPagarRecordFrame.InserirActionExecute(Sender: TObject);
begin
  inherited;
  status.ItemIndex := 0;
  DBCalendarData.Date := DuplicataData.BuscaData();
  DuplicataData.DuplicataPagarZQuery.FieldByName('parcela').AsString := '1';
  DuplicataData.DuplicataPagarZQuery.FieldByName('data_vencimento').AsString :=
    DBCalendarData.Date;

end;

procedure TDuplicataPagarRecordFrame.SalvarActionExecute(Sender: TObject);
begin
  if PlanoContaLookup.Text = '' then begin
    ShowMessage('Selecione um Plano de Contas!');
  end else begin
    inherited;
  end;
end;

initialization
  {$I duplicatapagarrecordfr.lrs}

end.
